Unless you also post a description of your algorithm (a wikipedia page for example), we're in no position to even guess how you screwed up.
Some decent formatting wouldn't go amiss in the meantime.
Not to mention pruning out dead or useless code.
Code:
$ gcc -Wall -Wextra foo.c
foo.c: In function ‘main’:
foo.c:18:13: warning: variable ‘pos’ set but not used [-Wunused-but-set-variable]
int i, j, pos, I;
^
foo.c:16:7: warning: unused variable ‘y’ [-Wunused-variable]
int y[10] = { 0 };
^
foo.c:15:13: warning: variable ‘c’ set but not used [-Wunused-but-set-variable]
int n, r, c, no_e, S, n0, n1;
^
As for the problem, add some debug code to examine the state as you go (or just use a debugger).
You should be able to work through the problem on paper in step with the code. When you find paper answer != code answer, you've found a bug!
Whether that bug is in the code or on the paper is for you to figure out.
Anyway,
Code:
#include <stdio.h>
void dumpMat1(int pass, int E[10][10]) {
printf("DEBUG PASS=%d\n", pass);
for ( int r = 0 ; r < 10 ; r++ ) {
for ( int c = 0 ; c < 10 ; c++ ) {
printf("%d ", E[r][c]);
}
printf("\n");
}
}
int main()
{
int n, r, c, no_e, S, n0, n1;
int y[10] = { 0 };
int i, j, pos, I;
int Imax = 10;
int E[10][10] = { 0 };
int H[4][8] = {
{0, 1, 0, 1, 1, 0, 0, 1},
{1, 1, 1, 0, 0, 1, 0, 0},
{0, 0, 1, 0, 0, 1, 1, 1},
{1, 0, 0, 1, 1, 0, 1, 0}
};
int M[8] = { 1, 1, 0, 1, 0, 1, 0, 1 }; // Error codeword
int t[8];
n = 8;
r = 4;
c = 8;
//Decoding using Message passing in Erasure channel
no_e = 0;
S = 0;
pos = 0;
I = 0;
while (I < Imax) {
no_e = 0;
for (j = 0; j < r; j++) {
S = 0;
for (i = 0; i < n; i++) {
E[j][i] = -1;
S = S + H[i][j] * M[i];
}
for (i = 0; i < n; i++)
if (H[j][i] == 1)
E[j][i] = (S + M[i]) % 2;
} //Finishing an entire matrix traverse
///printf("\n\n\n");
dumpMat1(I,E); // something useful, instead of masses of blank lines
for (j = 0; j < n; j++) {
n1 = 0;
n0 = 0;
for (i = 0; i < r; i++) { //bcz E[i][j] can be -1 also
if ((E[i][j] == 0 || E[i][j] == 1))
(E[i][j] == 0) ? n0++ : n1++;
}
if (n0 == n1)
(M[j] == 0) ? n0++ : n1++;
t[j] = (n0 >= n1) ? 0 : 1;
if (t[j] != M[j])
M[j] = (M[j] + 1) % 2; //bit flipping
}
for (j = 0; j < r; j++) {
S = 0;
for (i = 0; i < n; i++)
S = S + H[j][i] * M[i];
if (S % 2 != 0) {
no_e++;
break;
}
}
if (no_e == 0)
break;
I = I + 1;
}
printf("\n\n\nThe corrected Code Word is(%d): \n\n", I);
for (i = 0; i < n; i++)
printf("%d\t", M[i]);
printf("\n");
}
Your first task is to figure out if each iteration of your E matrix is correct.